草庐IT

异步 接收

全部标签

javascript - 如何使用 setTimeout 等待变量加载,同时接收 HTTP 请求!

我在JavaScript中创建了一个函数,每100毫秒检查一次是否加载了全局变量。当加载变量时,函数将返回值变量如下图。在我的代码中,我使用JavaScript中的HTTP服务器,当特定的HTTP请求具有特定的时,变量将被加载header到达我的服务器。functioncheckVariable(){if(myvar!=null){returnmyVar;}else{window.setTimeout("checkVariable();",100);}}我在一段代码中使用这个函数是这样的://arithmetisoperations...[1]myVar=checkVariable()

javascript - 在 firebase 云函数中返回多个异步函数的 promise ?

所以我有一个调用2个异步函数的Firebase云函数。exports.someFunction=functions.firestore.document('some/path').onCreate(event=>{asyncFunction1();asyncFunction2();});asyncFunction1和asyncFunction2都返回一个promise。现在,Firebasedictates我们应该Resolvefunctionsthatperformasynchronousprocessing(alsoknownas"backgroundfunctions")byre

javascript - Firebase:异步/等待事务

我正在尝试对事务使用异步/等待。但是出现错误“参数“updateFunction”不是有效函数。”vardocRef=admin.firestore().collection("docs").doc(docId);lettransaction=admin.firestore().runTransaction();letdoc=awaittransaction.get(docRef);if(!doc.exists){throw("docnotfound");}varnewLikes=doc.data().likes+1;awaittransaction.update(docRef,{li

javascript - 使用 i18next 的异步语言选择器

我正在使用http://jamuhl.github.com/i18next本地化静态网站。我的初始化脚本是:jQuery(function($){varsetLng=$.url().param('setLng');if(setLng){language_complete=setLng.split("-");}else{language_complete=navigator.language.split("-");}language=(language_complete[0]);console.log("Ispeak(root):%s",language);i18n.init({lng:

javascript - 并行 API 请求的异步模块错误

我是node.js的初学者,现在我正在尝试获取一些API的结果。我正在使用异步模块(https://github.com/caolan/async)来并行处理请求,以便对其进行优化。问题是代码返回错误,每次都指向不同API调用中的不同行(“callback(err,data)”行)这是错误的:if(called)thrownewError("Callbackwasalreadycalled.");^Error:Callbackwasalreadycalled.我正在使用以下函数来请求API:functiongetData(s,apiURL,getURL,callback){varht;

javascript - 链接两个异步 jQuery 函数时如何完全避开 jQuery promise ?

我看过很多关于新的EMCApromises的教程,它们提倡避免使用jQuery库中的“promises”。他们通常说您可以通过执行以下操作来躲避他们:Promise.resolve($.getJSON(url,params));//voila!thejQuerypromiseis"gone"!但是,当我必须将两个异步jQuery函数链接在一起时,这实际上不起作用。我如何在不使用jQuery的then()或.when()的情况下将两个getJSON调用(第二个调用取决于第一个调用)链接在一起?相反,我只想使用Promise.all等。我认为一个类似的问题会交织jquery和EMCApro

javascript - SyntaxError : Unexpected identifier in selenium-webdriver/lib/http. js:454 异步执行(命令)

我最近安装了selenium-webdriverjavascript(node)client3.6.0步骤如下;#npminstallwebdriver#npminstallselenium-webdriver#npminstallchromedriver将它们安装到我的项目文件夹中然后制作一个名为“library.js”的js文件varwebdriver=require('selenium-webdriver');vardriver=newwebdriver.Builder().forBrowser('chrome').build();By=webdriver.By;until=we

javascript - 我可以在异步函数的 try/catch block 中使用多个 'await' 吗?

即asyncasyncfunction(){try{awaitmethod1();awaitmethod2();}catch(error){console.log(error);}}给定method1()和method2()是异步函数。每个await方法都应该有一个try/catchblock吗?有没有更简洁的方式来写这个?我试图避免“.then”和“.catch”链接。 最佳答案 当等待在await一元运算符右侧创建的promise时,使用一个包含多个await操作的try/catchblock很好:await运算符存储其父asy

javascript - 异步函数返回 promise ,而不是值(value)

我正在尝试了解async/await如何与promises一起工作。代码asyncfunctionlatestTime(){constbl=awaitweb3.eth.getBlock('latest');console.log(bl.timestamp);//Returnsaprimitiveconsole.log(typeofbl.timestamp.then=='function');//Returnsfalse-notapromisereturnbl.timestamp;}consttime=latestTime();//Promise{}问题据我所知,await应该是阻塞的,

javascript - 在 Firebase 云函数中包含异步函数 (eslint "Parsing error: Unexpected token function")

问题如何将async辅助方法添加到CloudFunctionsindex.js文件中?在将fs.writefile转换为Promise时,需要一个async函数才能使用await,如本文所述StackOverflow帖子:fs.writeFileinapromise,asynchronous-synchronousstuff.但是,lint不赞成在exports函数之外向index.js文件添加额外的方法。错误第84行引用辅助函数asyncfunctionwriteFile。Users/adamhurwitz/coinverse/coinverse-cloud-functions/fu